package com.ftg.learn.day12.question;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * 工人
 *
 * @author 布衣
 */
public class Worker {

    private String name;
    private int age;
    private BigDecimal salary;

    public Worker() {
    }

    public Worker(String name, int age, BigDecimal salary) {
        this.name = name;
        this.age = age;
        this.salary = salary;
    }

    public void work(){
        System.out.println("工人" + name + "正在工作...");
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof Worker) {
            Worker params = (Worker) o;
            if (this.getName().equals(params.getName()) &&
                    this.getAge() == params.getAge() &&
                    this.getSalary().equals(params.getSalary())){
                return true;
            }
        }
        return false;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public BigDecimal getSalary() {
        return salary;
    }

    public void setSalary(BigDecimal salary) {
        this.salary = salary;
    }

    public static void main(String[] args) {
        List<Worker> ws = new ArrayList<>();
        Worker w = new Worker();
        w.setName("张三");
        w.setAge(20);
        w.setSalary(new BigDecimal("10000"));
        ws.add(w);
        ws.add(new Worker("李四", 20, new BigDecimal("10000")));

        for (int i = 0; i < ws.size(); i++) {
            ws.get(i).work();
        }

        ws.forEach(x->x.work());
        ws.forEach(Worker::work);
    }
}
